package com.santu.edu.supporter.biz.order.pojo.dto;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.santu.edu.supporter.biz.order.pojo.enums.OrderStatusEnum;
import com.santu.edu.supporter.biz.order.pojo.enums.SendGoodType;
import com.santu.edu.supporter.biz.order.pojo.params.OrderAddParam;
import com.santu.edu.supporter.biz.order.pojo.po.OrderPO;
import lombok.Data;
import lombok.experimental.Accessors;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author luoyaoqi
 * @createTime 2024/3/18
 * @description
 */
@Data
@Accessors(chain = true)
public class OrderDTO {

    /**
     * 订单id
     */
    private String orderId;

    /**
     * 用户id
     */
    private String userId;

    /**
     * 商品集合
     */
    private List<GoodInfo> goodList;

    /**
     * 总价格
     */
    private BigDecimal price;

    /**
     * 备注信息
     */
    private String remarkInfo;

    /**
     * 送货地址id
     */
    private String addressId;

    /**
     * 送货方式
     */
    private SendGoodType sendGoodType;

    /**
     * 送货id
     */
    private String sendGoodId;

    /**
     * 订单状态
     */
    private OrderStatusEnum orderStatus;

    /**
     * 支付时间
     */
    private String payTime;

    public static OrderDTO createItem(String userId, String orderId, OrderAddParam addParam) {
        return new OrderDTO()
                .setOrderId(orderId)
                .setUserId(userId)
                .setGoodList(addParam.getGoodList())
                .setPrice(addParam.getPrice())
                .setRemarkInfo(addParam.getRemarkInfo())
                .setAddressId(addParam.getAddressId())
                .setSendGoodType(SendGoodType.UNSHIPPED)
                .setOrderStatus(OrderStatusEnum.TO_BE_PAID);
    }

    public static OrderDTO createItem(OrderPO item) {
        return new OrderDTO()
                .setOrderId(item.getOrderId())
                .setUserId(item.getUserId())
                .setGoodList(JSONArray.parseArray(item.getSendGoodId(), GoodInfo.class))
                .setPrice(item.getPrice())
                .setRemarkInfo(item.getRemarkInfo())
                .setAddressId(item.getAddressId())
                .setSendGoodType(SendGoodType.convert(item.getSendGoodType()))
                .setSendGoodId(item.getSendGoodId())
                .setOrderStatus(OrderStatusEnum.convert(item.getOrderStatus()))
                .setPayTime(item.getPayTime());
    }
}
